package com.asset.salesforce.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.asset.salesforce.dao.StockCategoryDaoImpl;
import com.asset.salesforce.dao.StockProductDaoImpl;
import com.asset.salesforce.dao.StockSkuDaoImpl;
import com.asset.salesforce.dao.StockSubCategoryDaoImpl;
import com.asset.salesforce.domain.Employee;
import com.asset.salesforce.domain.StockCategory;
import com.asset.salesforce.domain.StockProduct;
import com.asset.salesforce.domain.StockSku;
import com.asset.salesforce.domain.StockSubCategory;

@Service
@Transactional(readOnly=true)
public class InventoryService {
	
	@Autowired
	private StockCategoryDaoImpl stockCategoryDaoImpl;
	
	@Autowired
	private StockSubCategoryDaoImpl stockSubCategoryDaoImpl;
	
	@Autowired
	private StockProductDaoImpl stockProductDaoImpl;
	@Autowired
	private StockSkuDaoImpl stockSkuDaoImpl;
	
	@Transactional(readOnly=false)
	public void addStockCategory(StockCategory stockCategory) {
		stockCategoryDaoImpl.saveOrupdate(stockCategory);
	}
	
	@Transactional(readOnly=false)
	public void addStockSubCategory(StockSubCategory stockSubCategory) {
		stockSubCategoryDaoImpl.saveOrupdate(stockSubCategory);
	}
	
	@Transactional(readOnly=false)
	public void addStockProduct(StockProduct stockProduct) {
		stockProductDaoImpl.saveOrupdate(stockProduct);
	}
	
	@Transactional(readOnly=false)
	public void addStockSku(StockSku stockSku) {
		stockSkuDaoImpl.saveOrupdate(stockSku);
	}
	
	@Transactional(readOnly=true)
	public List<StockCategory> getAllStockCategories(){
		return stockCategoryDaoImpl.getAll(new StockCategory());
	}
	
	@Transactional(readOnly=true)
	public List<StockCategory> getAllStockCategoriesByCompanyId(Employee employee){
		return stockCategoryDaoImpl.getAllStockCategoriesByCompanyId(employee);
	}
	
	@Transactional(readOnly=true)
	public List<StockSubCategory> getAllStockSubCategories(){
		return stockSubCategoryDaoImpl.getAll(new StockSubCategory());
	}
	
	@Transactional(readOnly=true)
	public List<StockSubCategory> getAllStockSubCategoriesByCompanyId(Employee employee){
		return stockSubCategoryDaoImpl.getAllStockSubCategoriesByCompanyId(employee);
	}
	
	
	@Transactional(readOnly=true)
	public List<StockProduct> getAllStockProducts(){
		return stockProductDaoImpl.getAll(new StockProduct());
	}
	@Transactional(readOnly=true)
	public List<StockProduct> getAllStockProductsByCompanyId(Employee employee){
		return stockProductDaoImpl.getAllStockProductsByCompanyId(employee);
	}
	
	@Transactional(readOnly=true)
	public List<StockSku> getAllStockSKUs(){
		return stockSkuDaoImpl.getAll(new StockSku());
	}
	
	@Transactional(readOnly=true)
	public List<StockSku> getAllStockSKUsByCompanyId(Employee employee){
		return stockSkuDaoImpl.getAllStockSKUsByCompanyId(employee);
	}
	@Transactional(readOnly=true)
	public StockCategory getStockCategoryById(Integer id){
		return stockCategoryDaoImpl.getById(id, new StockCategory());
	}
	
	@Transactional(readOnly=true)
	public StockSubCategory getStockSubCategoryById(Integer id){
		return stockSubCategoryDaoImpl.getById(id, new StockSubCategory());
	}
	
	@Transactional(readOnly=true)
	public StockProduct getStockProductById(Integer id){
		return stockProductDaoImpl.getById(id, new StockProduct());
	}
	
	@Transactional(readOnly=true)
	public StockSku getStockSKUById(Integer id){
		return stockSkuDaoImpl.getById(id, new StockSku());
	}
	@Transactional(readOnly=true)
	public List<StockSku> getAllSKUsByEmpId(Integer empId,Integer productId){
		return stockSkuDaoImpl.getAllSKUsByEmpIdAndProductId(empId, productId);
	}

	
	@Transactional(readOnly=false)
	public void editStockCategory(StockCategory stockCategory){
		 stockCategoryDaoImpl.saveOrupdate(stockCategory);
	}
	
	@Transactional(readOnly=false)
	public void editStockSubCategory(StockSubCategory stockSubCategory){
		 stockSubCategoryDaoImpl.saveOrupdate(stockSubCategory);
	}
	
	@Transactional(readOnly=false)
	public void editStockProduct(StockProduct stockProduct ){
		 stockProductDaoImpl.saveOrupdate(stockProduct);
	}
	
	@Transactional(readOnly=false)
	public void editStockSKU(StockSku stockSku){
		stockSkuDaoImpl.saveOrupdate(stockSku);
	}
	
	@Transactional(readOnly=false)
	public void deleteStockCategory(StockCategory stockCategory){
		 stockCategoryDaoImpl.delete(stockCategory);
	}
	
	@Transactional(readOnly=false)
	public void deleteStockSubCategory(StockSubCategory stockSubCategory){
		 stockSubCategoryDaoImpl.delete(stockSubCategory);
	}
	
	@Transactional(readOnly=false)
	public void deleteStockProduct(StockProduct stockProduct ){
		 stockProductDaoImpl.delete(stockProduct);
	}
	
	@Transactional(readOnly=false)
	public void deleteStockSKU(StockSku stockSku){
		stockSkuDaoImpl.delete(stockSku);
	}

	@Transactional(readOnly=true)
	 public StockProduct getProductsById(Integer id){
		return stockProductDaoImpl.getProductsById(id);
	}
	@Transactional(readOnly=false)
	public StockCategory getByName(String name){
		return stockCategoryDaoImpl.getByName(name);
	}
	
	@Transactional(readOnly=false)
	public StockCategory getByCode(String code){
		return stockCategoryDaoImpl.getByCode(code);
	}
	@Transactional(readOnly=false)
	public StockProduct getByProName(String name){
		return stockProductDaoImpl.getByProName(name);
	}
	
	@Transactional(readOnly=false)
	public StockProduct getByProCode(String code){
		return stockProductDaoImpl.getByProCode(code);
	}
	@Transactional(readOnly=false)
	public StockSku getBySkuName(String name){
		return stockSkuDaoImpl.getBySkuName(name);
	}
	
	@Transactional(readOnly=false)
	public StockSku getBySkuCode(String code){
		return stockSkuDaoImpl.getBySkuCode(code);
	}
	@Transactional(readOnly=false)
	public StockSubCategory getBySubName(String name){
		return stockSubCategoryDaoImpl.getBySubName(name);
	}
	
	@Transactional(readOnly=false)
	public List<StockSubCategory> getAllSubCategoriesByCategory(Integer stockCategoryId,Integer employeeId){
		return stockSubCategoryDaoImpl.getAllSubCategoriesByCategory(stockCategoryId,employeeId);
	}
	@Transactional(readOnly=false)
	public List<StockCategory> getAllCategoriesByEmployeeId(Integer employeeId) {
		return stockCategoryDaoImpl.getAllCategoriesByEmployeeId(employeeId);
	}
	@Transactional(readOnly=false)
	public List<StockProduct> getAllProductsBySubCategory(Integer stockSubCategoryId,Integer employeeId) {
		return stockProductDaoImpl.getAllProductsBySubCategory(stockSubCategoryId, employeeId);
	}

}
